package com.qingdai.controller;

import com.qingdai.emuns.User;
import com.qingdai.entities.CommonResult;
import com.qingdai.service.UserService;
import com.qingdai.utils.JwtUtil;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;

//常用代码段模板
public class ATemplate {
    @Resource
    private JwtUtil jwtUtil;
    @Resource
    private UserService userService;

    public CommonResult getUserByUser(HttpServletRequest request) {
        CommonResult result = jwtUtil.getUserIdByJwt(request);
        if (result.getCode() == 200) {
            Integer jwtUserId = (Integer) result.getData();
            User user = userService.getById(jwtUserId);
            return new CommonResult<>(200,"",user);
        }else {
            return result;
        }
    }
}
